package com.power.using.sharlockchat.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;

import com.power.using.sharlockchat.R;
import com.power.using.sharlockchat.interfaces.DialogClick;
import com.power.using.sharlockchat.utils.ToastUtils;
import com.power.using.sharlockchat.utils.loading.IosAlertDialog;
import com.power.using.sharlockchat.utils.loading.LoadingDialog;

import me.yokeyword.fragmentation_swipeback.SwipeBackFragment;

/*
*
*  侧滑功能fragment 继承的 base
* */
public class BaseBackFragment extends SwipeBackFragment {

    private static final String TAG = "Fragmentation";

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setParallaxOffset(0.5f);
    }

    protected void initToolbarBack(Toolbar toolbar) {
        toolbar.findViewById(R.id.toolbar_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                _mActivity.onBackPressed();
            }
        });
        toolbar.findViewById(R.id.toolbar_iv_menu).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(_mActivity, "点击了menu", Toast.LENGTH_SHORT).show();
            }
        });
//        toolbar.setNavigationIcon(R.drawable.titlebar_back_selector);
//        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                _mActivity.onBackPressed();
//            }
//        });
    }
    //Toast显示
    protected void showShortToast(String string) {
        ToastUtils.showShortToast(getActivity(), string);
    }

    protected void showLoadingDialog(){
        LoadingDialog.showLoadingDialog(_mActivity);
    }

    protected void showLoadingDialog(String message){
        LoadingDialog.showLoadingDialog(_mActivity,message);
    }

    protected void cancelLoadingDialog(){
        LoadingDialog.cancelLoadingDialog();
    }

    protected void showAlertOnlyPos(Context context, String title, String msg , final DialogClick dialogClick) {
        new IosAlertDialog(context).builder()

                .setTitle(title)
                .setMsg(msg)
                .setOnlyPostivite("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogClick.PositiveMessage();
                    }
                }).show();
    }


    protected void showAlertOnlyPos(Context context, String title, String msg ) {
        new IosAlertDialog(context).builder()
                .setTitle(title)
                .setMsg(msg)
                .setOnlyPostivite("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                }).show();
    }

    protected void showAlertPos(Context context, String title, String msg, final DialogClick dialogClick) {
        new IosAlertDialog(context).builder()
                .setMsg(msg)
                .setPositiveButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogClick.PositiveMessage();
                    }
                }).setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogClick.NegativeMessage();
            }
        }).show();
    }

    protected void showAlertDialogNoMsg(Context context, String titleContent, String message, final DialogClick dialogClick) {

        new IosAlertDialog(context).builder().setTitle(titleContent)
                .setPositiveButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogClick.PositiveMessage();
                    }
                }).setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogClick.NegativeMessage();
            }
        }).show();
    }

    protected void showAlertDialog(Context context, String titleContent, String message, final DialogClick dialogClick) {

        new IosAlertDialog(context).builder().setTitle(titleContent)
                .setMsg(message)
                .setPositiveButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogClick.PositiveMessage();
                    }
                }).setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogClick.NegativeMessage();
            }
        }).show();
    }




    @Override
    public boolean onBackPressedSupport() {
        return super.onBackPressedSupport();
    }
}
